import os
import rtconfig
from building import *

cwd = GetCurrentDir()
libs = []
# add general drivers

src = Split('''
TouchGFX/target/generated/OSWrappers_RTT.cpp
TouchGFX/target/generated/STM32DMA.cpp
TouchGFX/target/STM32TouchController.cpp
TouchGFX/target/TouchGFXGPIO.cpp
TouchGFX/target/generated/TouchGFXConfiguration.cpp
TouchGFX/target/generated/TouchGFXGeneratedHAL.cpp
TouchGFX/target/TouchGFXHAL.cpp
TouchGFX/App/app_touchgfx.c
TouchGFX/App/sample_touchgfx.c
''')
path  = [cwd + '/TouchGFX']
path += [cwd + '/TouchGFX/target']
path += [cwd + '/TouchGFX/target/generated']
path += [cwd + '/Middlewares/ST/touchgfx/framework/include']

if rtconfig.CROSS_TOOL == 'gcc':
    libpath = [cwd + '/Middlewares/ST/touchgfx/lib/core/cortex_m7/gcc']
    libs += ['touchgfx-float-abi-hard']
    src += [cwd + '/Middlewares/ST/touchgfx/lib/core/cortex_m7/gcc/libtouchgfx-float-abi-hard.a']
elif rtconfig.CROSS_TOOL == 'keil':
    libpath = [cwd + '/Middlewares/ST/touchgfx/lib/core/cortex_m7/Keil']
    libs += ['touchgfx_core.lib']
    src += [cwd + '/Middlewares/ST/touchgfx/lib/core/cortex_m7/Keil/touchgfx_core.lib']
elif rtconfig.CROSS_TOOL == 'iar':
    libpath = [cwd + '/Middlewares/ST/touchgfx/lib/core/cortex_m7/IAR8.x']
    libs += ['touchgfx_core.a']
    src += [cwd + '/Middlewares/ST/touchgfx/lib/core/cortex_m7/IAR8.x/touchgfx_core.a']

group = DefineGroup('TouchGFX_app', src, depend = ['ART_PI_TouchGFX_LIB'], CPPPATH = path, LIBS = libs, LIBPATH = libpath)

# add TouchGFX generated
genSrc = Glob('./TouchGFX/generated/fonts/src/*.cpp')
genSrc += Glob('./TouchGFX/generated/gui_generated/src/*/*.cpp')
genSrc += Glob('./TouchGFX/generated/images/src/*.cpp')
genSrc += Glob('./TouchGFX/generated/texts/src/*.cpp')

genPath = [cwd + '/TouchGFX/generated/fonts/include']
genPath += [cwd + '/TouchGFX/generated/gui_generated/include']
genPath += [cwd + '/TouchGFX/generated/images/include']
genPath += [cwd + '/TouchGFX/generated/texts/include']

group = group + DefineGroup('TouchGFX_generated', genSrc, depend = ['ART_PI_TouchGFX_LIB'], CPPPATH = genPath)

# add TouchGFX resource
resSrc = Glob('./TouchGFX/generated/images/src/*/*.cpp')

group = group + DefineGroup('TouchGFX_resource', resSrc, depend = ['ART_PI_TouchGFX_LIB'])

# add TouchGFX gui
guiSrc = Glob('./TouchGFX/gui/src/*/*.cpp')
guiPath = [cwd + '/TouchGFX/gui/include']

group = group + DefineGroup('TouchGFX_gui', guiSrc, depend = ['ART_PI_TouchGFX_LIB'], CPPPATH = guiPath)

Return('group')
